Package es.csic.iiia.fabregues.dip
Class Player
java.lang.Object
es.csic.iiia.fabregues.dip.Observer
es.csic.iiia.fabregues.dip.Player
public abstract class Player extends Observer
Player of the game.
- Author:
- Angela Fabregues, IIIA-CSIC, fabregues@iiia.csic.es
-
Field Summary
Fields Modifier and Type Field Description protected Power
me
protected int
passcode
protected java.lang.String
preferredPower
The power that this player prefers to play. -
Constructor Summary
-
Method Summary
Modifier and Type Method Description void
afterOldPhase()
does something afterOldPhasevoid
beforeNewPhase()
plays and sends the orders to the serverPower
getMe()
java.lang.String
getPreferredPower()
Returns the name of the power that this player would prefer to play.void
handleSlo(java.lang.String winner)
ends the game when someone has won.boolean
isDead()
void
mapConfirmation()
confirms the mapvoid
missingOrder(java.lang.String[] message)
abstract java.util.List<Order>
play()
plays selecting the orders to write if returned orders == null, orders are not send.void
proposeDraw()
Call this method to propose a draw.void
reconnectionConfirmation(java.lang.String powerName, int passcode)
confirms the reconnectionvoid
restart(IComm commImpl, java.lang.String powerName, java.lang.String password)
Player constructor for reconnectionvoid
sendOrders(java.util.List<Order> orders)
sends all orders to the servervoid
setMe(java.lang.String power)
abstract void
start()
starts the player when the powers are assignedvoid
startPlaying(java.lang.String power, int passcode, int pressLevel)
starts playingvoid
submissionError(java.lang.String[] message)
Methods inherited from class es.csic.iiia.fabregues.dip.Observer
exit, getBuildTimeLimit, getGame, getMoveTimeLimit, getName, getRetreatTimeLimit, getVersion, handleCCD, handleServerOFF, handleSMR, init, phaseEnd, receivedOrder, setGame, setMap, start, start, start
-
Field Details
-
preferredPower
protected java.lang.String preferredPowerThe power that this player prefers to play. After connecting to the server the player will send a message to the server to indicate its preference. There is no guarantee that the player will indeed be assigned this power, because this depends on the implementation of the server and on the preferences of the other players. -
me
-
passcode
protected int passcode
-
-
Constructor Details
-
Method Details
-
getMe
-
restart
public void restart(IComm commImpl, java.lang.String powerName, java.lang.String password) throws CommExceptionPlayer constructor for reconnection- Parameters:
ip
- of the serverport
- of the servername
- of the playerpowerName
- performed by the player in the previous connectionpassword
- of the player in the previous connection- Throws:
CommException
CommException
java.io.IOException
CommException
-
reconnectionConfirmation
public void reconnectionConfirmation(java.lang.String powerName, int passcode)confirms the reconnection- Parameters:
powerName
-passcode
-
-
mapConfirmation
confirms the map- Overrides:
mapConfirmation
in classObserver
- Throws:
CommException
-
startPlaying
public void startPlaying(java.lang.String power, int passcode, int pressLevel)starts playing- Parameters:
power
-passcode
-pressLevel
-
-
beforeNewPhase
plays and sends the orders to the server- Specified by:
beforeNewPhase
in classObserver
- Throws:
CommException
-
sendOrders
sends all orders to the server- Parameters:
orders
-- Throws:
CommException
-
proposeDraw
public void proposeDraw()Call this method to propose a draw. If all players that are not yet eliminated propose a draw in the same phase, then the server ends the game. -
handleSlo
public void handleSlo(java.lang.String winner)ends the game when someone has won. -
afterOldPhase
public void afterOldPhase()does something afterOldPhase- Specified by:
afterOldPhase
in classObserver
-
play
plays selecting the orders to write if returned orders == null, orders are not send. Then you should send them using sendOrders()- Returns:
- list of orders
-
start
public abstract void start()starts the player when the powers are assigned -
setMe
public void setMe(java.lang.String power) -
submissionError
public void submissionError(java.lang.String[] message) -
missingOrder
public void missingOrder(java.lang.String[] message) -
isDead
public boolean isDead() -
getPreferredPower
public java.lang.String getPreferredPower()Returns the name of the power that this player would prefer to play. May return null if this player has no preferred power.- Returns:
- the preferredPower
-